package com.wsc.juc_001.c_004;

/**
 * synchronized(t.class)是单例的吗，一般情况下是，正常classloader只会加载一个对象，但是不用同的classloader可以加载t对象，但是彼此间不能访问
 */
public class Synchronized_04 {
    public static int count = 10;

    public static synchronized void m(){//这里等同于Synchronized(T.class)
        count--;
        System.out.println(Thread.currentThread().getName()+"count = " +count);
    }

    public static void mm(){
        synchronized (Synchronized_04.class){//这边写是否合理？
            count--;
            System.out.println(Thread.currentThread().getName() + " count = "+ count);
        }
    }

    public static void main(String[] args) {
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    Synchronized_04.mm();
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
